﻿using Abp.Domain.Repositories;
using Abp.ObjectMapping;
using Abp.Runtime.Caching;
using Abp.UI;
using AVIS.OutBound.Contents.Cache;
using AVIS.OutBound.Contents.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVIS.OutBound.Contents
{
    /// <summary>
    /// 内容CMS的应用服务
    /// </summary>
    public class ContentAppService : OutBoundAppServiceBase, IContentAppService
    {
        #region 构造函数
        private readonly IContentManager _contentManager;
        private readonly IObjectMapper _objectMapper;

        public ContentAppService(
            IContentManager ContentManager,
            IObjectMapper objectMapper)
        {
            _contentManager = ContentManager;
            _objectMapper = objectMapper;

        }
        #endregion

        /// <summary>
        /// 获取首页的banner
        /// </summary>
        /// <returns></returns>
        public IList<BannerOutput> GetIndexBanner()
        {
            // TODO 需要对内容CMS考虑不同的设备终端（PC和触屏）

            var banner = _contentManager.GetBanner();
            var outputs = _objectMapper.Map<List<BannerOutput>>(banner);
            return outputs;
        }

        /// <summary>
        /// 获取最新的特惠活动
        /// </summary>
        /// <returns></returns>
        public IList<PromotionListOutput> GetLasterPromotions()
        {
            var list = _contentManager.GetLasterPromotions();

            return _objectMapper.Map<List<PromotionListOutput>>(
                list.Where(p => !string.IsNullOrWhiteSpace(p.LinkImage))
            );
        }

        /// <summary>
        /// 获取特惠详情
        /// </summary>
        /// <param name="input">请求参数</param>
        /// <returns></returns>
        public PromotionOutput Promotion(PromotionInput input)
        {
            var data = _contentManager.GetPromotion(input.Id);
            var output = _objectMapper.Map<PromotionOutput>(data);
            return output;
        }
    }
}
